package com.sky.mapper;

import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
    void insert(Orders orders);
    /**
     * 根据状态和时间查询订单
     * @param status
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    void update(Orders orders);
    /**
     * 根据状态查询订单
     * @param status
     * @return
     */
    @Select("select* from orders where status=#{status}")
    List<Orders> selectByStatus(Integer status);
    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from order_detail where order_id = #{id}")
    Orders getById(Long id);
    /*
    已送达状态和一天时间内查表
     */
    @Select("select sum(amount) from orders where status = #{status} and order_time between #{begin} and #{end}")
    Double sumByMap(Map map);
    /**
     * 查询指定时间区间内的订单总数量
     * @param map
     * @return
     */
    @Select("select count(id) from orders where order_time between #{begin} and #{end}")
    Integer countByDate(Map map);
    /*

     */
    @Select("select count(id) from orders where status = #{status} and order_time between #{begin} and #{end}")
    Integer validOrderCount(Map map);
    /*
    查top10
     */
    @Select("SELECT SUM(od.number) AS totalSales FROM orders o JOIN order_detail od ON o.id = od.order_id WHERE o.status = 5 AND o.order_time BETWEEN #{begin} AND #{end} GROUP BY od.name ORDER BY totalSales DESC LIMIT 10")
    List sumTOP10(Map map);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
